/*
* Uds_Server.h
* Last edited: 27.08.2014
* Author: David Noack
*/

#ifndef UDOM_SERVER_H_
#define UDOM_SERVER_H_

/** Unix Domain Socket needs a file to work, this is the path to this file*/
#define UDS_FILE "/tmp/sock.uds"
#define UDS_LOG "Log_Uds"

#include "Com_Interface.h"
#include "MyThreadClass.h"
#include <sys/un.h>


/**
\class Uds_Server
\brief Implements a Unix-domain-socket server for prngd.
*/
class Uds_Server : public Com_Interface, MyThreadClass{

	public:

		/**Contructor*/
		Uds_Server(Prngd_State state);

		/**Destructor*/
		~Uds_Server()
		{
			if(prngd != NULL)
				delete prngd;
			if(create_socket != 0)
				close(create_socket);
		};

	private:

		/**Unix socket for the uds connection.*/
		int create_socket;
		/** Communication socket.*/
		int new_socket;
		/** Var for the address length of the server*/
		socklen_t addrlen;
		/** Struct for the server address.*/
		struct sockaddr_un address;

		/** See doc for My_ThreadClass.*/
		virtual void thread_listen(pthread_t parent_th);
		/** See doc for My_ThreadClass.*/
		virtual void thread_work();


};


#endif /* UDOM_SERVER_H_ */

